﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PloobsEngine.SceneControl;

namespace Etapa1.SteeringExperiments
{
    public class Evade: Steering
    {
        public Evade(IObject target, float panicDistance)
            : base(BehaviorType.flee)
        {
            _flee = new Flee(target, panicDistance);
            this.objTarget = target;            
        }
        
        private IObject objTarget;        
        private Flee _flee;
        private float predictionWeight = 1;

        public float PredictionWeight
        {
            get { return predictionWeight; }
            set { predictionWeight = value; }
        }

        public float PanicDistance
        {
            get { return _flee.PanicDistance; }
            set { _flee.PanicDistance= value; }
        }

        public IObject ObjTarget
        {
            get { return objTarget; }
            set { objTarget = value; }
        }

        public override Microsoft.Xna.Framework.Vector3 CalculateSteering(SteeringEntityInfo entity)
        {
            Vector3 ToEvader ;
            ToEvader = objTarget.Position - entity.Obj.Position;            

            float LookAheadTime = ToEvader.Length() /
                    (entity.MaxVelocity / 2 + objTarget.PhysicObject.Velocity.Length());

            _flee.Target = objTarget.Position + objTarget.PhysicObject.Velocity * LookAheadTime * predictionWeight;

            return _flee.CalculateSteering(entity);
        }
    }
}
